package com.guigusuqi.commonutils.utils;

import org.apache.commons.lang3.ObjectUtils;

import java.util.Date;

public class CalculateTimeDifferenceUtils
{
    public static Integer calculateTimeDifference(Date startDate, Date endDate)
    {
        //  毫秒ms
        Integer diff = Math.toIntExact(Math.abs(endDate.getTime() - startDate.getTime()));
        Integer diffSeconds = diff / 1000;
        Integer diffMinutes = diff / (60 * 1000);
        Integer diffHours = diff / (60 * 60 * 1000);
        Integer diffDays = diff / (24 * 60 * 60 * 1000);
        Integer diffMonths = diffDays / 30;
        return diffHours;
    }

    public static Integer calculateMonthDifference(Date startDate, Date endDate)
    {
        //  毫秒ms
        Integer diff = Math.toIntExact(Math.abs(endDate.getTime() - startDate.getTime()));
        Integer diffDays = diff / (24 * 60 * 60 * 1000);
        return diffDays / 30;
    }

    public static Integer calculateDaysDifference(Date startDate, Date endDate)
    {
        //  毫秒ms
        Integer diff = Math.toIntExact(Math.abs(endDate.getTime() - startDate.getTime()));
        return diff / (24 * 60 * 60 * 1000);
    }
}
